/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.zcm.modules.nbg.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.zcm.common.config.Global;
import com.zcm.common.persistence.Page;
import com.zcm.common.web.BaseController;
import com.zcm.common.utils.StringUtils;
import com.zcm.modules.nbg.entity.NbgJuechechi;
import com.zcm.modules.nbg.service.NbgJuechechiService;

/**
 * 决策池Controller
 * @author www
 * @version 2018-10-02
 */
@Controller
@RequestMapping(value = "${adminPath}/nbg/nbgJuechechi")
public class NbgJuechechiController extends BaseController {

	@Autowired
	private NbgJuechechiService nbgJuechechiService;
	
	@ModelAttribute
	public NbgJuechechi get(@RequestParam(required=false) String id) {
		NbgJuechechi entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = nbgJuechechiService.get(id);
		}
		if (entity == null){
			entity = new NbgJuechechi();
		}
		return entity;
	}
	
	@RequiresPermissions("nbg:nbgJuechechi:view")
	@RequestMapping(value = {"list", ""})
	public String list(NbgJuechechi nbgJuechechi, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<NbgJuechechi> page = nbgJuechechiService.findPage(new Page<NbgJuechechi>(request, response), nbgJuechechi); 
		model.addAttribute("page", page);
		return "modules/nbg/nbgJuechechiList";
	}

	@RequiresPermissions("nbg:nbgJuechechi:view")
	@RequestMapping(value = "form")
	public String form(NbgJuechechi nbgJuechechi, Model model) {
		model.addAttribute("nbgJuechechi", nbgJuechechi);
		return "modules/nbg/nbgJuechechiForm";
	}

	@RequiresPermissions("nbg:nbgJuechechi:edit")
	@RequestMapping(value = "save")
	public String save(NbgJuechechi nbgJuechechi, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, nbgJuechechi)){
			return form(nbgJuechechi, model);
		}
		nbgJuechechiService.save(nbgJuechechi);
		addMessage(redirectAttributes, "保存决策池成功");
		return "redirect:"+Global.getAdminPath()+"/nbg/nbgJuechechi/?repage";
	}
	
	@RequiresPermissions("nbg:nbgJuechechi:edit")
	@RequestMapping(value = "delete")
	public String delete(NbgJuechechi nbgJuechechi, RedirectAttributes redirectAttributes) {
		nbgJuechechiService.delete(nbgJuechechi);
		addMessage(redirectAttributes, "删除决策池成功");
		return "redirect:"+Global.getAdminPath()+"/nbg/nbgJuechechi/?repage";
	}

}